
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>其他算法 · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../java基础/原码补码反码.html" />
    
    
    <link rel="prev" href="扫描线种子填充算法.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../doc/常用网站.html">
            
                <a href="../doc/常用网站.html">
            
                    
                    常用网站
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../常用软件/常用软件和框架.html">
            
                <a href="../常用软件/常用软件和框架.html">
            
                    
                    常用软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../doc/开发规范.html">
            
                <a href="../doc/开发规范.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../doc/开源软件.html">
            
                <a href="../doc/开源软件.html">
            
                    
                    开源软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../doc/Android常用代码.html">
            
                <a href="../doc/Android常用代码.html">
            
                    
                    Android常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../源码阅读/源码阅读配置.html">
            
                <a href="../源码阅读/源码阅读配置.html">
            
                    
                    源码阅读
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../源码阅读/其他框架源码.html">
            
                <a href="../源码阅读/其他框架源码.html">
            
                    
                    其他框架源码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../产品经理/产品经理.html">
            
                <a href="../产品经理/产品经理.html">
            
                    
                    产品经理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../设计模式/模式详解.html">
            
                <a href="../设计模式/模式详解.html">
            
                    
                    模式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../设计模式/mvc等.html">
            
                <a href="../设计模式/mvc等.html">
            
                    
                    mvc等
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    基本算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    常用数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="算法术语.html">
            
                <a href="算法术语.html">
            
                    
                    算法术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="排序算法.html">
            
                <a href="排序算法.html">
            
                    
                    排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="查找算法.html">
            
                <a href="查找算法.html">
            
                    
                    查找算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="大数相加.html">
            
                <a href="大数相加.html">
            
                    
                    大数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="集合的所有子集.html">
            
                <a href="集合的所有子集.html">
            
                    
                    获得集合的所有子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="扫描线种子填充算法.html">
            
                <a href="扫描线种子填充算法.html">
            
                    
                    扫描线种子填充算法
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.10.8" data-path="其他算法.html">
            
                <a href="其他算法.html">
            
                    
                    其他算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    Java部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    原码补码反码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../java基础/java常用代码.html">
            
                <a href="../java基础/java常用代码.html">
            
                    
                    java常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../java基础/JVM详解.html">
            
                <a href="../java基础/JVM详解.html">
            
                    
                    JVM详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../java基础/类加载机制.html">
            
                <a href="../java基础/类加载机制.html">
            
                    
                    类加载机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../java基础/内存模型.html">
            
                <a href="../java基础/内存模型.html">
            
                    
                    内存模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../java基础/GC机制.html">
            
                <a href="../java基础/GC机制.html">
            
                    
                    GC机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../java基础/对象内存布局.html">
            
                <a href="../java基础/对象内存布局.html">
            
                    
                    对象内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../java基础/继承多态.html">
            
                <a href="../java基础/继承多态.html">
            
                    
                    继承和多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../java基础/相等判断.html">
            
                <a href="../java基础/相等判断.html">
            
                    
                    相等判断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../java基础/Java容器类.html">
            
                <a href="../java基础/Java容器类.html">
            
                    
                    Java容器类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../java基础/Java枚举.html">
            
                <a href="../java基础/Java枚举.html">
            
                    
                    Java枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../java基础/自定义异常.html">
            
                <a href="../java基础/自定义异常.html">
            
                    
                    自定义异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../java基础/深度拷贝.html">
            
                <a href="../java基础/深度拷贝.html">
            
                    
                    深度拷贝
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../java基础/泛型详解.html">
            
                <a href="../java基础/泛型详解.html">
            
                    
                    泛型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../java基础/线程详解.html">
            
                <a href="../java基础/线程详解.html">
            
                    
                    线程详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.16" data-path="../java基础/java注解.html">
            
                <a href="../java基础/java注解.html">
            
                    
                    注解详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.17" data-path="../java基础/数据解析.html">
            
                <a href="../java基础/数据解析.html">
            
                    
                    数据解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.18" data-path="../java基础/java8新特性.html">
            
                <a href="../java基础/java8新特性.html">
            
                    
                    Java8新特性
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../android基础/android零散知识.html">
            
                <a href="../android基础/android零散知识.html">
            
                    
                    Android部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../android基础/基础控件使用.html">
            
                <a href="../android基础/基础控件使用.html">
            
                    
                    基础控件使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../android基础/android零散知识.html">
            
                <a href="../android基础/android零散知识.html">
            
                    
                    Android零散知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../android基础/android坐标体系.html">
            
                <a href="../android基础/android坐标体系.html">
            
                    
                    Android坐标体系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../android基础/APP的启动流程.html">
            
                <a href="../android基础/APP的启动流程.html">
            
                    
                    APP启动流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../android基础/View加载流程.html">
            
                <a href="../android基础/View加载流程.html">
            
                    
                    View加载流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../android基础/事件分发机制.html">
            
                <a href="../android基础/事件分发机制.html">
            
                    
                    事件分发机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../android基础/控件绘制流程.html">
            
                <a href="../android基础/控件绘制流程.html">
            
                    
                    控件绘制流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.8" data-path="../android基础/常用shape.html">
            
                <a href="../android基础/常用shape.html">
            
                    
                    常用shape
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.9" data-path="../android基础/进程通信.html">
            
                <a href="../android基础/进程通信.html">
            
                    
                    进程通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.10" data-path="../通信方式/通信方式详解.html">
            
                <a href="../通信方式/通信方式详解.html">
            
                    
                    通信方式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.11" data-path="../android基础/Binder详解.html">
            
                <a href="../android基础/Binder详解.html">
            
                    
                    Binder详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.12" data-path="../android基础/Handler详解.html">
            
                <a href="../android基础/Handler详解.html">
            
                    
                    Handle详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.13" data-path="../android基础/Fragment详解.html">
            
                <a href="../android基础/Fragment详解.html">
            
                    
                    Fragment详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.14" data-path="../android基础/Activity详解.html">
            
                <a href="../android基础/Activity详解.html">
            
                    
                    Activity详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.15" data-path="../android基础/BroadcastReceiver.html">
            
                <a href="../android基础/BroadcastReceiver.html">
            
                    
                    BroadcastReceiver详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.16" data-path="../android基础/Service服务.html">
            
                <a href="../android基础/Service服务.html">
            
                    
                    Service详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.17" data-path="../android基础/动画详解.html">
            
                <a href="../android基础/动画详解.html">
            
                    
                    动画详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.18" data-path="../android基础/屏幕刷新机制.html">
            
                <a href="../android基础/屏幕刷新机制.html">
            
                    
                    屏幕刷新机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.19" data-path="../android基础/屏幕适配.html">
            
                <a href="../android基础/屏幕适配.html">
            
                    
                    屏幕适配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.20" data-path="../android基础/图片加载详解.html">
            
                <a href="../android基础/图片加载详解.html">
            
                    
                    图片加载详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.21" data-path="../android基础/WebView详解.html">
            
                <a href="../android基础/WebView详解.html">
            
                    
                    WebView详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.22" data-path="../android基础/沉浸式.html">
            
                <a href="../android基础/沉浸式.html">
            
                    
                    沉浸式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.23" data-path="../android基础/相机模块.html">
            
                <a href="../android基础/相机模块.html">
            
                    
                    相机模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.24" data-path="../android基础/地图模块.html">
            
                <a href="../android基础/地图模块.html">
            
                    
                    地图模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.25" data-path="../android基础/Androidstudio插件开发.html">
            
                <a href="../android基础/Androidstudio插件开发.html">
            
                    
                    Androidstudio插件开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.26" data-path="../android基础/Apk插件化开发.html">
            
                <a href="../android基础/Apk插件化开发.html">
            
                    
                    Apk插件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.27" data-path="../android基础/App组件化开发.html">
            
                <a href="../android基础/App组件化开发.html">
            
                    
                    App组件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.28" data-path="../android基础/sdk开发.html">
            
                <a href="../android基础/sdk开发.html">
            
                    
                    sdk开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.29" data-path="../android基础/APP优化.html">
            
                <a href="../android基础/APP优化.html">
            
                    
                    APP优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.30" data-path="../android基础/项目参数配置.html">
            
                <a href="../android基础/项目参数配置.html">
            
                    
                    项目参数配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.31" data-path="../android基础/App发布.html">
            
                <a href="../android基础/App发布.html">
            
                    
                    App发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.32" data-path="../android基础/Android外挂.html">
            
                <a href="../android基础/Android外挂.html">
            
                    
                    Android外挂
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.33" data-path="../android基础/Android字节码插桩.html">
            
                <a href="../android基础/Android字节码插桩.html">
            
                    
                    Android字节码插桩
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.34" data-path="../android基础/智能家居.html">
            
                <a href="../android基础/智能家居.html">
            
                    
                    智能家居
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../python/python爬虫.html">
            
                <a href="../python/python爬虫.html">
            
                    
                    python爬虫
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../gradle/Groovy.html">
            
                <a href="../gradle/Groovy.html">
            
                    
                    Groovy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../kotlin/kotlin部分.html">
            
                <a href="../kotlin/kotlin部分.html">
            
                    
                    kotlin部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../flutter/flutter部分.html">
            
                <a href="../flutter/flutter部分.html">
            
                    
                    flutter部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../native/ccpp.html">
            
                <a href="../native/ccpp.html">
            
                    
                    native部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../native/Linux.html">
            
                <a href="../native/Linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../native/ccpp.html">
            
                <a href="../native/ccpp.html">
            
                    
                    cCpp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../native/NDK.html">
            
                <a href="../native/NDK.html">
            
                    
                    NDK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../native/系统编译剪裁.html">
            
                <a href="../native/系统编译剪裁.html">
            
                    
                    系统编译剪裁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5" data-path="../native/音视频.html">
            
                <a href="../native/音视频.html">
            
                    
                    音视频
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.6" data-path="../native/音视频第三方库.html">
            
                <a href="../native/音视频第三方库.html">
            
                    
                    音视频第三方库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.7" data-path="../native/相关代码.html">
            
                <a href="../native/相关代码.html">
            
                    
                    相关代码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../server/服务器部分.html">
            
                <a href="../server/服务器部分.html">
            
                    
                    服务器部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../webDev/web部分.html">
            
                <a href="../webDev/web部分.html">
            
                    
                    web部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../人工智能/人工智能相关概念.html">
            
                <a href="../人工智能/人工智能相关概念.html">
            
                    
                    人工智能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../面试真题/极飞.html">
            
                <a href="../面试真题/极飞.html">
            
                    
                    面试真题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >其他算法</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x8BA9;&#x4E09;&#x4E2A;&#x7EBF;&#x7A0B;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x6253;&#x5370;-1-100-&#xFF0C;"><b>1. </b>&#x8BA9;&#x4E09;&#x4E2A;&#x7EBF;&#x7A0B;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x6253;&#x5370; 1-100 &#xFF0C;</a></li><ul><li><span class="title-icon "></span><a href="#&#x601D;&#x8DEF;1-synchronized--wait--notifyall"><b>1.1. </b>&#x601D;&#x8DEF;1 synchronized + wait + notifyAll</a></li><li><span class="title-icon "></span><a href="#&#x601D;&#x8DEF;2-&#x4F11;&#x7720;-&#x6761;&#x4EF6;&#x5224;&#x65AD;"><b>1.2. </b>&#x601D;&#x8DEF;2 &#x4F11;&#x7720;+ &#x6761;&#x4EF6;&#x5224;&#x65AD;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x91CD;&#x590D;&#x5143;&#x7D20;"><b>2. </b>&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x91CD;&#x590D;&#x5143;&#x7D20;</a></li><li><span class="title-icon "></span><a href="#&#x53CD;&#x8F6C;&#x6570;&#x7EC4;"><b>3. </b>&#x53CD;&#x8F6C;&#x6570;&#x7EC4;</a></li><li><span class="title-icon "></span><a href="#&#x751F;&#x4EA7;&#x8005;&#x6D88;&#x606F;&#x8005;&#x6A21;&#x578B;"><b>4. </b>&#x751F;&#x4EA7;&#x8005;&#x6D88;&#x606F;&#x8005;&#x6A21;&#x578B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x65B9;&#x5F0F;1-synchronized--objectwait--objectnotifyall---&#x539F;&#x7406;"><b>4.1. </b>&#x65B9;&#x5F0F;1 synchronized + object.wait() + object.notifyAll() - &#x539F;&#x7406;</a></li><li><span class="title-icon "></span><a href="#&#x65B9;&#x5F0F;2-&#x5C01;&#x88C5;&#x5DE5;&#x5177;-blockingqueue--&#x751F;&#x4EA7;&#x73AF;&#x5883;"><b>4.2. </b>&#x65B9;&#x5F0F;2 &#x5C01;&#x88C5;&#x5DE5;&#x5177; BlockingQueue -&#x751F;&#x4EA7;&#x73AF;&#x5883;</a></li></ul><li><span class="title-icon "></span><a href="#&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x3001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><b>5. </b>&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x3001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;</a></li><ul><li><span class="title-icon "></span><a href="#&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"><b>5.1. </b>&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;</a></li><li><span class="title-icon "></span><a href="#&#x7B80;&#x5355;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><b>5.2. </b>&#x7B80;&#x5355;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;</a></li><li><span class="title-icon "></span><a href="#&#x53D8;&#x6001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><b>5.3. </b>&#x53D8;&#x6001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;</a></li></ul></ul></div><a href="#&#x8BA9;&#x4E09;&#x4E2A;&#x7EBF;&#x7A0B;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x6253;&#x5370;-1-100-&#xFF0C;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x8BA9;&#x4E09;&#x4E2A;&#x7EBF;&#x7A0B;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x6253;&#x5370;-1-100-&#xFF0C;"><a name="&#x8BA9;&#x4E09;&#x4E2A;&#x7EBF;&#x7A0B;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x6253;&#x5370;-1-100-&#xFF0C;" class="anchor-navigation-ex-anchor" href="#&#x8BA9;&#x4E09;&#x4E2A;&#x7EBF;&#x7A0B;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x6253;&#x5370;-1-100-&#xFF0C;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x8BA9;&#x4E09;&#x4E2A;&#x7EBF;&#x7A0B;&#x6309;&#x7167;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x6253;&#x5370; 1-100 &#xFF0C;</h1>
<p>&#x51E0;&#x4E2A;&#x7EBF;&#x7A0B;&#x8F6E;&#x6D41;&#x6253;&#x5370;&#x3002; 
&#x5982;&#x4F55;&#x8BA9;n&#x4E2A;&#x7EBF;&#x7A0B;&#x5FAA;&#x73AF;&#x4EA4;&#x66FF;&#x6253;&#x5370;</p>
<h2 id="&#x601D;&#x8DEF;1-synchronized--wait--notifyall"><a name="&#x601D;&#x8DEF;1-synchronized--wait--notifyall" class="anchor-navigation-ex-anchor" href="#&#x601D;&#x8DEF;1-synchronized--wait--notifyall"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x601D;&#x8DEF;1 synchronized + wait + notifyAll</h2>
<pre><code class="lang-text">&#x601D;&#x8DEF;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x9501;&#x673A;&#x5236; 
private static final Object lockObj = new Object();
private static volatile int printInt = 1;
public static void main(String[] args)  {
    Thread threadFirst = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized (lockObj) {
                while (printInt &lt;= 100) {
                    if (printInt % 3 == 1) {
                        System.out.println(&quot;\r\n&#x7EBF;&#x7A0B;&#x540D;&#x5B57;=&quot; + Thread.currentThread().getName() + &quot;;i==&quot; + printInt );
                        printInt++ ;
                    }
                    lockObj.notifyAll();
                    if (printInt == 101) {
                        break;
                    }

                    try {
                        lockObj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }
    });

    Thread threadSecond = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized (lockObj) {
                while (printInt &lt;= 100) {
                    if (printInt % 3 == 2) {
                        System.out.println(&quot;&#x7EBF;&#x7A0B;&#x540D;&#x5B57;=&quot; + Thread.currentThread().getName() + &quot;;i==&quot; + printInt );
                        printInt++ ;
                    }
                    lockObj.notifyAll();
                    try {
                        lockObj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    });

    Thread threadThird = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized (lockObj) {
                while (printInt &lt;= 100) {
                    if (printInt % 3 == 0) {
                        System.out.println(&quot;&#x7EBF;&#x7A0B;&#x540D;&#x5B57;=&quot; + Thread.currentThread().getName() + &quot;;i==&quot; + printInt );
                        printInt++ ;
                    }
                    lockObj.notifyAll();
                    try {
                        lockObj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    });
    threadFirst.start();
    threadSecond.start();
    threadThird.start();
}
</code></pre>
<h2 id="&#x601D;&#x8DEF;2-&#x4F11;&#x7720;-&#x6761;&#x4EF6;&#x5224;&#x65AD;"><a name="&#x601D;&#x8DEF;2-&#x4F11;&#x7720;-&#x6761;&#x4EF6;&#x5224;&#x65AD;" class="anchor-navigation-ex-anchor" href="#&#x601D;&#x8DEF;2-&#x4F11;&#x7720;-&#x6761;&#x4EF6;&#x5224;&#x65AD;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x601D;&#x8DEF;2 &#x4F11;&#x7720;+ &#x6761;&#x4EF6;&#x5224;&#x65AD;</h2>
<pre><code class="lang-text">public class PrintRunnable implements Runnable{
     private static  int printValut =1;
     /**
      * &#x4E0B;&#x4E00;&#x4E2A;&#x5C06;&#x8981;&#x6253;&#x5370;&#x7684;&#x7EBF;&#x7A0B;&#x5E8F;&#x53F7;,
      * &#x7528;&#x6765;&#x786E;&#x4FDD;&#x7EBF;&#x7A0B; &#x662F;&#x6309;&#x7167; 0 &#xFF0C;1 &#xFF0C;2 &#x987A;&#x5E8F;&#x6765;&#x6267;&#x884C;&#x7684;
      */
     private static volatile int nextPrintSeq =0;
    private static Lock lock=new ReentrantLock();

    /**
     * &#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x5E8F;&#x53F7;
     */
    private int seq;
    /**
     * &#x7EBF;&#x7A0B;&#x603B;&#x6570;
     */
    private int nThread;

    PrintRunnable(int seq, int nThread) {
        this.seq = seq;
        this.nThread=nThread;
    }

    @Override
    public void run() {
        final int MAXVALUE =100 ;
        while(printValut &lt;=MAXVALUE){

            while (nextPrintSeq !=seq){
                LockSupport.parkNanos(1);// &#x4F11;&#x7720;&#x7B49;&#x5F85;
            }

            lock.lock();
            if(nextPrintSeq !=seq){
                // &#x91CD;&#x65B0;&#x5FAA;&#x73AF;&#xFF0C;&#x7EE7;&#x7EED;&#x7B49;&#x5F85;
                lock.unlock();
                continue;
            }

            int value= printValut;
            for(int i=0; i&lt;5 &amp; value&lt;= MAXVALUE; i++,value++){
                // &#x901A;&#x8FC7;&#x4FEE;&#x6539; 5&#xFF0C;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0; &#x7EBF;&#x7A0B;&#x6253;&#x5370;&#x6548;&#x679C; 123&#xFF0C;456&#xFF0C;789&#xFF0C;&#x7B49;
                System.out.println(&quot;threadSeq: &quot;+seq+&quot;, value: &quot;+value);
                printValut++ ;
            }

            nextPrintSeq =(seq+1)%nThread;
            lock.unlock();
        }
    }
}

public static void main(String[] args) {
    int nThread=3;
    for(int i=0;i&lt;nThread;i++){
        Thread thread=new Thread(new PrintRunnable(i, nThread));
        thread.start();
    }
}
</code></pre>
<h1 id="&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x91CD;&#x590D;&#x5143;&#x7D20;"><a name="&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x91CD;&#x590D;&#x5143;&#x7D20;" class="anchor-navigation-ex-anchor" href="#&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x91CD;&#x590D;&#x5143;&#x7D20;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x91CD;&#x590D;&#x5143;&#x7D20;</h1>
<p>&#x6570;&#x7EC4;&#x53BB;&#x91CD;</p>
<pre><code class="lang-text">&#x7ED9;&#x5B9A; nums = [0,0,1,1,1,2,2,3,3,4],
&#x51FD;&#x6570;&#x5E94;&#x8BE5;&#x8FD4;&#x56DE;&#x65B0;&#x7684;&#x957F;&#x5EA6; 5, &#x5E76;&#x4E14;&#x539F;&#x6570;&#x7EC4; nums &#x7684;&#x524D;&#x4E94;&#x4E2A;&#x5143;&#x7D20;&#x88AB;&#x4FEE;&#x6539;&#x4E3A; 0, 1, 2, 3, 4&#x3002;
&#x4F60;&#x4E0D;&#x9700;&#x8981;&#x8003;&#x8651;&#x6570;&#x7EC4;&#x4E2D;&#x8D85;&#x51FA;&#x65B0;&#x957F;&#x5EA6;&#x540E;&#x9762;&#x7684;&#x5143;&#x7D20;&#x3002;

&#x601D;&#x8DEF;&#xFF1A;&#x5B9A;&#x4E49;&#x4E24;&#x4E2A;&#x6307;&#x9488;&#xFF0C;&#x5C06;&#x6570;&#x7EC4;&#x770B;&#x505A;&#x4E24;&#x4E2A;&#x90E8;&#x5206;&#xFF0C;&#x5C06;&#x524D;&#x9762;&#x90E8;&#x5206;&#x4E0E;&#x540E;&#x9762;&#x90E8;&#x5206;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#xFF0C;
&#x5982;&#x679C;&#x53D1;&#x73B0;&#x4E0D;&#x540C;&#xFF0C;&#x5C31;&#x5C06;&#x540E;&#x9762;&#x7684;&#x4E0D;&#x540C;&#x9879;&#x62F7;&#x8D1D;&#x5230;&#x524D;&#x9762;&#x3002;
&#x6839;&#x636E;&#x793A;&#x610F;&#x56FE;&#x548C;&#x6253;&#x5370;&#x8FC7;&#x7A0B;&#xFF0C;&#x5F88;&#x5BB9;&#x6613;&#x7406;&#x89E3;

public static void main(String[] args) {
    int[] values = {0, 0, 0, 0, 0, 2, 2 ,3};
    int size = removeDuplicates1(values);
    System.out.print(&quot;\r\n&#x6709;&#x6548;&#x6570;&#x5B57;&#x957F;&#x5EA6;=&quot;+size +&quot;  --&gt;&quot;);
    for(int value : values){
        System.out.print( &quot;  &quot;+value);
    }
}

private static int removeDuplicates1(int[] nums) {
    if(nums.length == 0) {
        return 0;
    }
    int indexA = 0;
    for(int indexB = 1; indexB &lt; nums.length; indexB++){
        showArray(nums);
        System.out.print(&quot;&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;&quot;+indexA+&quot;  &quot;+indexB  );
        if(nums[indexA] != nums[indexB]){
            System.out.print(&quot;&#x503C;&#x4E0D;&#x540C;--&gt;&quot;+nums[indexA]+&quot;  &quot;+nums[indexB] +&quot;  &#x9700;&#x8981;&#x4FEE;&#x6539;&quot;);
            indexA++;
            nums[indexA] = nums[indexB];
        }else{
            System.out.print(&quot;&#x503C;&#x76F8;&#x540C;--&gt;&quot;+nums[indexA]+&quot;  &quot;+nums[indexB]  +&quot;  &#x5FFD;&#x7565;&#x672C;&#x8F6E;&quot;);
        }
        showArray(nums);
    }
    //&#x5FAA;&#x73AF;&#x7ED3;&#x675F;&#x4E4B;&#x540E;&#xFF0C;indexA&#x662F;&#x7D22;&#x5F15;&#xFF0C;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#x8981;+1
    return indexA + 1;
}

private static void showArray(int[] values ){
    System.out.println();
    for(int value : values){
        System.out.print(value+&quot; &quot;);
    }
    System.out.println();
}

0 0 0 0 0 2 2 3 
&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;0  1&#x503C;&#x76F8;&#x540C;--&gt;0  0  &#x5FFD;&#x7565;&#x672C;&#x8F6E;
0 0 0 0 0 2 2 3 

0 0 0 0 0 2 2 3 
&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;0  2&#x503C;&#x76F8;&#x540C;--&gt;0  0  &#x5FFD;&#x7565;&#x672C;&#x8F6E;
0 0 0 0 0 2 2 3 

0 0 0 0 0 2 2 3 
&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;0  3&#x503C;&#x76F8;&#x540C;--&gt;0  0  &#x5FFD;&#x7565;&#x672C;&#x8F6E;
0 0 0 0 0 2 2 3 

0 0 0 0 0 2 2 3 
&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;0  4&#x503C;&#x76F8;&#x540C;--&gt;0  0  &#x5FFD;&#x7565;&#x672C;&#x8F6E;
0 0 0 0 0 2 2 3 

0 0 0 0 0 2 2 3 
&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;0  5&#x503C;&#x4E0D;&#x540C;--&gt;0  2  &#x9700;&#x8981;&#x4FEE;&#x6539;
0 2 0 0 0 2 2 3 

0 2 0 0 0 2 2 3 
&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;1  6&#x503C;&#x76F8;&#x540C;--&gt;2  2  &#x5FFD;&#x7565;&#x672C;&#x8F6E;
0 2 0 0 0 2 2 3 

0 2 0 0 0 2 2 3 
&#x672C;&#x8F6E;&#x7D22;&#x5F15;--&gt;1  7&#x503C;&#x4E0D;&#x540C;--&gt;2  3  &#x9700;&#x8981;&#x4FEE;&#x6539;
0 2 3 0 0 2 2 3 

&#x6709;&#x6548;&#x6570;&#x5B57;&#x957F;&#x5EA6;=3  --&gt;  0  2  3  0  0  2  2  3
</code></pre>
<p><img src="../pics/&#x6570;&#x7EC4;&#x53BB;&#x91CD;.png" alt=""></p>
<h1 id="&#x53CD;&#x8F6C;&#x6570;&#x7EC4;"><a name="&#x53CD;&#x8F6C;&#x6570;&#x7EC4;" class="anchor-navigation-ex-anchor" href="#&#x53CD;&#x8F6C;&#x6570;&#x7EC4;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x53CD;&#x8F6C;&#x6570;&#x7EC4;</h1>
<pre><code class="lang-text">&#x4F8B;&#x5982;&#x539F;&#x6570;&#x7EC4;&#x4E3A;&#xFF1A;{&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;},&#x90A3;&#x4E48;&#x7FFB;&#x8F6C;&#x540E;&#x7684;&#x6570;&#x7EC4;&#x4E3A;  {&quot;d&quot;,&quot;c&quot;,&quot;b&quot;,&quot;a&quot;}&#x3002;

void reverseArray(int[] array){
    for (int i = 0, max = array.length - 1; i &lt; max; i++, max--) {
        int temp = array[i];
        array[i] = array[max];
        array[max] = temp;
    }
}
</code></pre>
<h1 id="&#x751F;&#x4EA7;&#x8005;&#x6D88;&#x606F;&#x8005;&#x6A21;&#x578B;"><a name="&#x751F;&#x4EA7;&#x8005;&#x6D88;&#x606F;&#x8005;&#x6A21;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x751F;&#x4EA7;&#x8005;&#x6D88;&#x606F;&#x8005;&#x6A21;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x751F;&#x4EA7;&#x8005;&#x6D88;&#x606F;&#x8005;&#x6A21;&#x578B;</h1>
<pre><code class="lang-text">&#x751F;&#x4EA7;&#x8005;&#x548C;&#x6D88;&#x8D39;&#x8005;&#x95EE;&#x9898;&#x662F;&#x7EBF;&#x7A0B;&#x6A21;&#x578B;&#x4E2D;&#x7684;&#x7ECF;&#x5178;&#x95EE;&#x9898;&#xFF1A;
&#x751F;&#x4EA7;&#x8005;&#x548C;&#x6D88;&#x8D39;&#x8005;&#x5728;&#x540C;&#x4E00;&#x65F6;&#x95F4;&#x6BB5;&#x5185;&#x5171;&#x7528;&#x540C;&#x4E00;&#x4E2A;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#xFF0C;
&#x751F;&#x4EA7;&#x8005;&#x5F80;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#x4E2D;&#x6DFB;&#x52A0;&#x4EA7;&#x54C1;&#xFF0C;&#x6D88;&#x8D39;&#x8005;&#x4ECE;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#x4E2D;&#x53D6;&#x8D70;&#x4EA7;&#x54C1;&#xFF0C;
&#x5F53;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#x4E3A;&#x7A7A;&#x65F6;&#xFF0C;&#x6D88;&#x8D39;&#x8005;&#x963B;&#x585E;&#xFF0C;&#x5F53;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#x6EE1;&#x65F6;&#xFF0C;&#x751F;&#x4EA7;&#x8005;&#x963B;&#x585E;&#x3002;
</code></pre>
<h2 id="&#x65B9;&#x5F0F;1-synchronized--objectwait--objectnotifyall---&#x539F;&#x7406;"><a name="&#x65B9;&#x5F0F;1-synchronized--objectwait--objectnotifyall---&#x539F;&#x7406;" class="anchor-navigation-ex-anchor" href="#&#x65B9;&#x5F0F;1-synchronized--objectwait--objectnotifyall---&#x539F;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>4.1. &#x65B9;&#x5F0F;1 synchronized + object.wait() + object.notifyAll() - &#x539F;&#x7406;</h2>
<pre><code class="lang-text">public static void main(String[] args) {
    // &#x6240;&#x6709;&#x7684;&#x751F;&#x4EA7;&#x8005;+&#x6D88;&#x8D39;&#x8005;&#x7EBF;&#x7A0B;&#x90FD;&#x4E89;&#x62A2;&#x8FD9;&#x4E00;&#x628A;&#x9501;
    Object lock =new Object();
    // &#x5B58;&#x653E;&#x4EA7;&#x54C1;&#x7684;&#x7F13;&#x51B2;&#x533A;
    List&lt;Integer&gt; linkedList = new ArrayList&lt;&gt;();

    for (int i = 0; i &lt; 5; i++) {
        new Thread(new Productor(linkedList, 20 ,lock) ,&quot;&#x751F;&#x4EA7;&#x8005;_&quot;+i).start();
    }

    for (int i = 0; i &lt; 10; i++) {
        new Thread(new Consumer(linkedList,  lock) ,&quot;&#x6D88;&#x8D39;&#x8005;_&quot;+i).start();
    }
}

public class Productor implements Runnable {
    private List&lt;Integer&gt; list;
    private int maxLength;
    private final Object lock ;
    private static boolean isRunning = true ;

    Productor(List&lt;Integer&gt; list, int maxLength , Object lock) {
        this.list = list;
        this.maxLength = maxLength;
        this.lock = lock;
    }

    @Override
    public void run() {
        while (isRunning) {
            synchronized (lock) {
                try {
                    while (list.size() &gt;= maxLength) {
                        System.out.println(Thread.currentThread().getName() + &quot;  &#x961F;&#x5217;&#x5DF2;&#x6EE1;&#xFF0C;&#x8FDB;&#x884C;wait&#x3002;&quot;+list.size());
                        lock.wait();
                        System.out.println(Thread.currentThread().getName() + &quot;  &#x9000;&#x51FA;wait&quot;);
                    }

                    int i = getRadomInt(0 ,100);
                    System.out.println( Thread.currentThread().getName() + &quot; &#x751F;&#x4EA7;&#x4E86;&#x6570;&#x636E;:  &quot; + i);
                    list.add(i);
                    lock.notifyAll();
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private int getRadomInt(int startNum, int endNum){
        return new  Random().nextInt(endNum - startNum + 1) + startNum;
    }
}

public class Consumer implements Runnable {
    private final Object lock ;
    private static boolean isRunning = true ;
    private List&lt;Integer&gt; list;
    Consumer(List&lt;Integer&gt; list ,Object lock) {
        this.list = list;
        this.lock = lock;
    }

    @Override
    public void run() {
        while (isRunning) {
            synchronized (lock) {
                try {
                    while (list.isEmpty()) {
                        System.out.println(Thread.currentThread().getName() + &quot;  &#x6570;&#x636E;&#x4E0D;&#x8DB3;&#xFF0C;&#x8FDB;&#x884C;wait&quot;);
                        lock.wait();
                        System.out.println(Thread.currentThread().getName() + &quot;  &#x6570;&#x636E;&#x5145;&#x8DB3;,&#x9000;&#x51FA;wait&quot;);
                    }
                    Integer element = list.remove(0);
                    System.out.println(Thread.currentThread().getName() + &quot;  &#x6D88;&#x8D39;&#x4E86;&#x6570;&#x636E;&#xFF1A;&quot; + element+&quot;  &#x6570;&#x636E;&#x5269;&#x4F59;&#x4E2A;&#x6570;=&quot;+list.size());
                    lock.notifyAll();
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
</code></pre>
<h2 id="&#x65B9;&#x5F0F;2-&#x5C01;&#x88C5;&#x5DE5;&#x5177;-blockingqueue--&#x751F;&#x4EA7;&#x73AF;&#x5883;"><a name="&#x65B9;&#x5F0F;2-&#x5C01;&#x88C5;&#x5DE5;&#x5177;-blockingqueue--&#x751F;&#x4EA7;&#x73AF;&#x5883;" class="anchor-navigation-ex-anchor" href="#&#x65B9;&#x5F0F;2-&#x5C01;&#x88C5;&#x5DE5;&#x5177;-blockingqueue--&#x751F;&#x4EA7;&#x73AF;&#x5883;"><i class="fa fa-link" aria-hidden="true"></i></a>4.2. &#x65B9;&#x5F0F;2 &#x5C01;&#x88C5;&#x5DE5;&#x5177; BlockingQueue -&#x751F;&#x4EA7;&#x73AF;&#x5883;</h2>
<pre><code class="lang-text">BlockingQueue &#x5185;&#x90E8;&#x63D0;&#x4F9B;&#x4E86;&#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#x7684;&#x961F;&#x5217;&#x8BBF;&#x95EE;&#x65B9;&#x5F0F;&#xFF0C;
&#x4F7F;&#x6211;&#x4EEC;&#x4E0D;&#x9700;&#x8981;&#x624B;&#x52A8;&#x53BB;&#x64CD;&#x4F5C; wait &#x548C; notifyAll &#x7B49;&#x7EC6;&#x8282;&#x3002;

BlockingQueue&lt;Integer&gt; queue = new LinkedBlockingQueue&lt;&gt;();
while (true) {
    Random random = new Random();
    int i = random.nextInt();
    System.out.println(&quot;&#x751F;&#x4EA7;&#x8005;&quot; + Thread.currentThread().getName() + &quot;&#x751F;&#x4EA7;&#x6570;&#x636E;&quot; + i);
    queue.put(i); //
    Thread.sleep(1000);
}

while (true) {
    Integer element = (Integer) queue.take();
    System.out.println(&quot;&#x6D88;&#x8D39;&#x8005;&quot; + Thread.currentThread().getName() + &quot;&#x6B63;&#x5728;&#x6D88;&#x8D39;&#x6570;&#x636E;&quot; + element);
    Thread.sleep(1000);
}
</code></pre>
<h1 id="&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x3001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><a name="&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x3001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;" class="anchor-navigation-ex-anchor" href="#&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x3001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x3001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;</h1>
<h2 id="&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"><a name="&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;" class="anchor-navigation-ex-anchor" href="#&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1. &#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;</h2>
<pre><code class="lang-text">&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x6307;&#x7684;&#x662F;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x6570;&#x5217;&#xFF1A;1&#x3001;1&#x3001;2&#x3001;3&#x3001;5&#x3001;8&#x3001;13&#x3001;21 ...
F(1)=1&#xFF0C;F(2)=1, F(n)=F(n-1)+F(n-2)&#xFF08;n&gt;=3&#xFF0C;n&#x2208;N*&#xFF09;
&#x4ECE;&#x7B2C;3&#x9879;&#x5F00;&#x59CB;&#xFF0C;&#x6BCF;&#x4E00;&#x9879;&#x90FD;&#x7B49;&#x4E8E;&#x524D;&#x4E24;&#x9879;&#x4E4B;&#x548C;&#x3002;
</code></pre>
<h2 id="&#x7B80;&#x5355;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><a name="&#x7B80;&#x5355;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;" class="anchor-navigation-ex-anchor" href="#&#x7B80;&#x5355;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><i class="fa fa-link" aria-hidden="true"></i></a>5.2. &#x7B80;&#x5355;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;</h2>
<pre><code class="lang-text">&#x4E00;&#x53EA;&#x9752;&#x86D9;&#x4E00;&#x6B21;&#x53EF;&#x4EE5;&#x8DF3;&#x4E0A;1&#x7EA7;&#x53F0;&#x9636;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x8DF3;&#x4E0A;2&#x7EA7;&#x3002;
&#x6C42;&#x8BE5;&#x9752;&#x86D9;&#x8DF3;&#x4E0A;&#x4E00;&#x4E2A;n&#x7EA7;&#x7684;&#x53F0;&#x9636;&#x603B;&#x5171;&#x6709;&#x591A;&#x5C11;&#x79CD;&#x8DF3;&#x6CD5;&#x3002; 
&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x8FD9;&#x4E2A;&#x76F8;&#x5F53;&#x4E8E;&#x53D8;&#x76F8;&#x7684;&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x3002;

&#x601D;&#x8DEF;&#xFF1A;&#x5047;&#x5982;&#x6709;5&#x7EA7;&#x53F0;&#x9636;&#xFF0C;&#x9752;&#x86D9;&#x8981;&#x4E48;&#x76F4;&#x63A5;&#x4ECE;4&#x7EA7;&#x4E0A;&#x8DF3;&#x4E00;&#x683C;&#x4E0A;&#x6765;&#xFF0C;&#x8981;&#x4E48;&#x4ECE;3&#x7EA7;&#x4E0A;&#x8DF3;&#x4E24;&#x683C;&#x4E0A;&#x6765;&#xFF0C;&#x6CA1;&#x6709;&#x522B;&#x7684;&#x65B9;&#x5F0F;&#x4E86;&#xFF0C;
&#x56E0;&#x6B64;&#x9752;&#x86D9;&#x53EA;&#x8981;&#x5173;&#x5FC3;&#x8DF3;&#x5230;4&#x7EA7;&#x7684;&#x603B;&#x65B9;&#x6CD5;&#x6570;&#x548C;&#x8DF3;&#x5230;&#x4E09;&#x7EA7;&#x7684;&#x603B;&#x65B9;&#x6CD5;&#x6570;&#x3002;

// &#x9012;&#x5F52;&#x65B9;&#x5F0F;(&#x6548;&#x7387;&#x4E0D;&#x5982;&#x975E;&#x9012;&#x5F52;)
private static long jumpFloor(int n) {
    if (n &lt; 0){
        throw new IllegalArgumentException(&quot;n can&apos;t be &lt; 0&quot;);
    }

    if(n &lt;= 2){
        return n;
    }

    else {
        return jumpFloor(n-1)+jumpFloor(n-2);
    }
}

// &#x975E;&#x9012;&#x5F52;&#x65B9;&#x5F0F;
private static long numWays(int n) {
    if (n &lt; 0){
        throw new IllegalArgumentException(&quot;n can&apos;t be &lt; 0&quot;);
    }

    if(n &lt;= 2){
        return n;
    }

    int pre_2 = 1, pre_1 = 2;
    for (int i = 3; i &lt;= n; i++) {
        int curent = pre_2 + pre_1;
        pre_2 = pre_1;
        pre_1 = curent;
    }
    return pre_1;
}
</code></pre>
<h2 id="&#x53D8;&#x6001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><a name="&#x53D8;&#x6001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;" class="anchor-navigation-ex-anchor" href="#&#x53D8;&#x6001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;"><i class="fa fa-link" aria-hidden="true"></i></a>5.3. &#x53D8;&#x6001;&#x9752;&#x86D9;&#x8DF3;&#x53F0;&#x9636;</h2>
<pre><code class="lang-text">&#x4E00;&#x53EA;&#x9752;&#x86D9;&#x4E00;&#x6B21;&#x53EF;&#x4EE5;&#x8DF3;1&#x9636;&#xFF0C;2&#x9636;&#x2026;n&#x9636;&#x3002;
&#x6C42;&#x8BE5;&#x9752;&#x86D9;&#x8DF3;&#x4E0A;&#x4E00;&#x4E2A;n &#x7EA7;&#x7684;&#x53F0;&#x9636;&#x603B;&#x5171;&#x6709;&#x591A;&#x5C11;&#x79CD;&#x8DF3;&#x6CD5;

&#x6570;&#x5B66;&#x5206;&#x6790;&#x8FC7;&#x7A0B;&#xFF1A;
&#x5C06; n &#x7EA7;&#x53F0;&#x9636;&#x7684;&#x8DF3;&#x6CD5;&#x8BB0;&#x4E3A; f(n)&#x3002;
n = 1 &#x65F6;&#xFF0C;  &#x8DF3;&#x6CD5;&#x53EA;&#x6709; 1 &#x79CD;&#xFF0C;&#x8BB0;&#x4E3A; f(1)&#xFF1B;
n = 2 &#x65F6;&#xFF0C;  &#x53EF;&#x4EE5;&#x5148;&#x8DF3; 1 &#x7EA7;&#xFF0C;&#x7136;&#x540E;&#x6709; f(1) &#x79CD;&#x8DF3;&#x6CD5;&#xFF1B;
            &#x6216;&#x8005;&#x76F4;&#x63A5;&#x8DF3; 2 &#x7EA7;&#xFF0C;&#x8FD9;&#x662F; 1 &#x79CD;&#x8DF3;&#x6CD5;&#xFF1B;
            &#x5171;&#x8BA1; f(2) = f(1)+1&#xFF1B;
n = 3 &#x65F6;&#xFF0C;  &#x53EF;&#x4EE5;&#x5148;&#x8DF3; 1 &#x7EA7;&#xFF0C;
            &#x7136;&#x540E;&#x6709; f(3-1) &#x79CD;&#x8DF3;&#x6CD5;&#xFF0C;&#x5373; f(2) &#x79CD;&#xFF1B;
            &#x6216;&#x8005;&#x5148;&#x8DF3; 2 &#x7EA7;&#xFF0C;&#x7136;&#x540E;&#x6709; f(3-2) &#x79CD;&#x8DF3;&#x6CD5;&#xFF0C;&#x5373; f(1) &#x79CD;&#xFF1B;
            &#x6216;&#x8005;&#x76F4;&#x63A5;&#x8DF3; 3 &#x7EA7;&#xFF0C;&#x8FD9;&#x662F; 1 &#x79CD;&#x8DF3;&#x6CD5;&#xFF1B;&#xFF1B;
            &#x5171;&#x8BA1; f(3) = f(2) + f(1) + 1 &#x79CD;&#xFF1B;

n &#x7EA7;&#x53F0;&#x9636;&#xFF0C;&#x5171;&#x6709;
f(n) = f(n-1) + f(n-2) + &#x2026; + f(1) + 1 &#x79CD;&#xFF1B;

n-1 &#x7EA7;&#x53F0;&#x9636;&#xFF0C;&#x5171;&#x6709;
f(n-1) = f(n-2) + &#x2026; + f(1) + 1 &#x79CD;&#xFF1B;

&#x4E24;&#x4E2A;&#x7B49;&#x5F0F;&#x76F8;&#x51CF;&#xFF0C;&#x5F97;&#x5230;&#xFF1A;
f(n) - f(n-1) = f(n-1)

&#x5373; f(n) = 2*f(n-1)

// &#x9012;&#x5F52;&#x65B9;&#x5F0F;(&#x6548;&#x7387;&#x4E0D;&#x5982;&#x975E;&#x9012;&#x5F52;)
public static int jumpFloorBT(int n) {
    if (n&lt;= 0){
        return 0;
    }

    if (n == 1){
        return 1;
    }

    else{
        return  2*jumpFloorBT(n-1);      
    }
}

// &#x7B80;&#x5316;&#x7248; (&#x975E;&#x9012;&#x5F52;&#x65B9;&#x5F0F;)
&#x6839;&#x636E;&#x4E0A;&#x8FF0;&#x5206;&#x6790;&#x7684;&#x7ED3;&#x679C; f(n) = 2*f(n-1) &#xFF0C;
&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x516C;&#x6BD4;&#x4E3A;2&#x7684;&#x7B49;&#x6BD4;&#x6570;&#x5217;&#x3002; &#x4E14;&#x7B26;&#x5408; f(n)=2^(n-1) &#xFF0C;
&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;Math&#x7684;&#x516C;&#x5F0F; 
prvate int jumpFloorBT2(int n) {
    return (int)Math.pow(2,(n-1));
}
</code></pre>
<footer class="page-footer"><span class="copyright">( no Copyright&#xFF0C;enjoy youself ! ) all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">The file was updated at :
2022-04-04 10:49:02
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="扫描线种子填充算法.html" class="navigation navigation-prev " aria-label="Previous page: 扫描线种子填充算法">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../java基础/原码补码反码.html" class="navigation navigation-next " aria-label="Next page: Java部分">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"其他算法","level":"1.10.8","depth":2,"next":{"title":"Java部分","level":"1.11","depth":1,"path":"chinese/java基础/原码补码反码.md","ref":"chinese/java基础/原码补码反码.md","articles":[{"title":"原码补码反码","level":"1.11.1","depth":2,"path":"chinese/java基础/原码补码反码.md","ref":"chinese/java基础/原码补码反码.md","articles":[]},{"title":"java常用代码","level":"1.11.2","depth":2,"path":"chinese/java基础/java常用代码.md","ref":"chinese/java基础/java常用代码.md","articles":[]},{"title":"JVM详解","level":"1.11.3","depth":2,"path":"chinese/java基础/JVM详解.md","ref":"chinese/java基础/JVM详解.md","articles":[]},{"title":"类加载机制","level":"1.11.4","depth":2,"path":"chinese/java基础/类加载机制.md","ref":"chinese/java基础/类加载机制.md","articles":[]},{"title":"内存模型","level":"1.11.5","depth":2,"path":"chinese/java基础/内存模型.md","ref":"chinese/java基础/内存模型.md","articles":[]},{"title":"GC机制","level":"1.11.6","depth":2,"path":"chinese/java基础/GC机制.md","ref":"chinese/java基础/GC机制.md","articles":[]},{"title":"对象内存布局","level":"1.11.7","depth":2,"path":"chinese/java基础/对象内存布局.md","ref":"chinese/java基础/对象内存布局.md","articles":[]},{"title":"继承和多态","level":"1.11.8","depth":2,"path":"chinese/java基础/继承多态.md","ref":"chinese/java基础/继承多态.md","articles":[]},{"title":"相等判断","level":"1.11.9","depth":2,"path":"chinese/java基础/相等判断.md","ref":"chinese/java基础/相等判断.md","articles":[]},{"title":"Java容器类","level":"1.11.10","depth":2,"path":"chinese/java基础/Java容器类.md","ref":"chinese/java基础/Java容器类.md","articles":[]},{"title":"Java枚举","level":"1.11.11","depth":2,"path":"chinese/java基础/Java枚举.md","ref":"chinese/java基础/Java枚举.md","articles":[]},{"title":"自定义异常","level":"1.11.12","depth":2,"path":"chinese/java基础/自定义异常.md","ref":"chinese/java基础/自定义异常.md","articles":[]},{"title":"深度拷贝","level":"1.11.13","depth":2,"path":"chinese/java基础/深度拷贝.md","ref":"chinese/java基础/深度拷贝.md","articles":[]},{"title":"泛型详解","level":"1.11.14","depth":2,"path":"chinese/java基础/泛型详解.md","ref":"chinese/java基础/泛型详解.md","articles":[]},{"title":"线程详解","level":"1.11.15","depth":2,"path":"chinese/java基础/线程详解.md","ref":"chinese/java基础/线程详解.md","articles":[]},{"title":"注解详解","level":"1.11.16","depth":2,"path":"chinese/java基础/java注解.md","ref":"chinese/java基础/java注解.md","articles":[]},{"title":"数据解析","level":"1.11.17","depth":2,"path":"chinese/java基础/数据解析.md","ref":"chinese/java基础/数据解析.md","articles":[]},{"title":"Java8新特性","level":"1.11.18","depth":2,"path":"chinese/java基础/java8新特性.md","ref":"chinese/java基础/java8新特性.md","articles":[]}]},"previous":{"title":"扫描线种子填充算法","level":"1.10.7","depth":2,"path":"chinese/常用算法/扫描线种子填充算法.md","ref":"chinese/常用算法/扫描线种子填充算法.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","fontsettings","tbfed-pagefooter","local-video","splitter","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"( no Copyright，enjoy youself ! )","modify_label":"The file was updated at :","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/常用算法/其他算法.md","mtime":"2022-04-04T02:49:02.900Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-04-04T03:47:09.782Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

